﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TnFormLibWithoutIcon
{
    public partial class TnFormNoIcon : UserControl
    {
        protected int bit = 0;
        protected Point p1;
        protected Point p2;
        public TnFormNoIcon()
        {
            InitializeComponent();
        }

        private void TnFormStandard_Load(object sender, EventArgs e)
        {
            this.ParentForm.FormBorderStyle = FormBorderStyle.None;
            this.Dock = DockStyle.Fill;
            this.ParentForm.TransparencyKey = System.Drawing.Color.FromArgb(121, 121, 121);
            //this.ptbIcon.Image = this.ParentForm.Icon.ToBitmap();
            this.lblCaption.Text = this.ParentForm.Text;
        }

        private void pnlCaptionBar_MouseDown(object sender, MouseEventArgs e)
        {
            bit = 1;
            p1 = this.ParentForm.Location;
            p2 = e.Location;
        }

        private void pnlCaptionBar_MouseMove(object sender, MouseEventArgs e)
        {
            if (bit == 1)
            {
                this.ParentForm.Location = new Point(this.ParentForm.Location.X + e.Location.X - p2.X, this.ParentForm.Location.Y + e.Location.Y - p2.Y);
                //MessageBox.Show(this.ParentForm.Location.X.ToString());
            }
        }

        private void pnlCaptionBar_MouseUp(object sender, MouseEventArgs e)
        {
            bit = 0;
            //MessageBox.Show(e.Location.X.ToString());

        }

        private void pnlCaptionBar_Paint(object sender, PaintEventArgs e)
        {
            this.SendToBack();
        }
    }
}
